<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="fn"  uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page import="kr.co.insoft.framework.config.Authorities" %>
<c:set var="CONTEXT">${pageContext.request.contextPath}</c:set>
<c:set var="cssUrl">${pageContext.request.contextPath}/resources/css</c:set>
<c:set var="jsUrl">${pageContext.request.contextPath}/resources/js</c:set>
<div class="col-sm-12 page-header custom-page-header">
	<h1><spring:message code="menu.configration.sev"/></h1>
	<small><spring:message code="menu.configration.sev.desc"/></small>
</div>
<form:form modelAttribute="sEVEntityModel" role="form" cssClass="form-horizontal">
	<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
	<form:input path="variableid" type="hidden"/>
	<div class="form-group">
		<spring:message code="configration.sev.variableTitle.desc" var="msgTitleDesc"/>
		<form:label path="variableName" cssClass="col-sm-2 control-label"><spring:message code="configration.sev.variableTitle"/></form:label>
		<div class="col-sm-10"><form:input path="variableName" cssClass="form-control" placeholder="${msgTitleDesc}" required='required'/></div>
	</div>
	<div class="form-group">
		<form:label path="variableDesc" cssClass="col-sm-2 control-label"><spring:message code="common.description"/></form:label>
		<spring:message code="common.description.desc" var="msgDesciptionDesc"/>
		<div class="col-sm-10"><form:textarea path="variableDesc"  cssClass="form-control" placeholder="${msgDesciptionDesc }"/></div>
	</div>
	<div class="form-group">
		<form:label path="variables" cssClass="col-sm-2 control-label"><spring:message code="configration.sev.variables"/></form:label>
		<div class="rows text-right col-sm-10"><button type="button" class="btn btn-primary addRows"><spring:message code="button.add.variable" /></button>
			<table class="table table-hover targetVariableMapTable topmargin20">
				<thead>
					<tr>
						<th class="col-sm-2"><spring:message code="configration.sev.type"/></th>
						<th class="col-sm-8"><spring:message code="configration.sev.attribute"/></th>
						<th class="col-sm-1"></th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${sEVEntityModel.variables }" var="variable" varStatus="status">
					<tr>
						<td class="col-sm-2 selectRows">
							<select class="form-control variableTypesSelect" name="tp" id="tp" required='required'>
								<option value=""><spring:message code="select.seleted.message"/></option>
								<c:choose>
									<c:when test="${variable.array}">
										<option value="String">String</option>
										<option value="Integer">Integer</option>
										<option value="Double">Double</option>
										<option value="Option">Option</option>
										<option value="Array" selected="selected">Array</option>
									</c:when>
									<c:otherwise>
										<c:choose>
											<c:when test="${variable.tp eq 'String'}">
												<option value="String" selected="selected">String</option>
												<option value="Integer">Integer</option>
												<option value="Double">Double</option>
												<option value="Option">Option</option>
												<option value="Array">Array</option>
											</c:when>
											<c:when test="${variable.tp eq 'Integer'}">
												<option value="String">String</option>
												<option value="Integer" selected="selected">Integer</option>
												<option value="Double">Double</option>
												<option value="Option">Option</option>
												<option value="Array">Array</option>
											</c:when>
											<c:when test="${variable.tp eq 'Double'}">
												<option value="String">String</option>
												<option value="Integer">Integer</option>
												<option value="Double" selected="selected">Double</option>
												<option value="Option">Option</option>
												<option value="Array">Array</option>
											</c:when>
											<c:when test="${variable.tp eq 'Option'}">
												<option value="String">String</option>
												<option value="Integer">Integer</option>
												<option value="Double">Double</option>
												<option value="Option" selected="selected">Option</option>
												<option value="Array">Array</option>
											</c:when>
										</c:choose>
									</c:otherwise>
								</c:choose>
							</select>
							<button type='button' class='btn btn-default addOptionButton variablePanel'><spring:message code='button.add.option'/></button>
						</td>
						<c:choose>
							<c:when test="${!variable.array and (variable.tp eq 'String') or (variable.tp eq 'Integer') or (variable.tp eq 'Double')  }">
								<td class="col-sm-8">
									<input type="text" class="form-control" id="title" name="title" required='required' placeholder="System Variable Name" value="${variable.title }"/>
									<div class="variableTypes variableTypeSingleValue panel panel-default variablePanel">
										<div class='panel-body'>
											<input type='text' class='form-control' name='val' id='val' placeholder='System Variable Value' value="${variable.val }"/>
										</div>
									</div>
								</td>
							</c:when>
							<c:when test="${!variable.array and variable.tp eq 'Option' }">
								<td class="col-sm-8">
									<input type="text" class="form-control" name="title" id="title" required='required' placeholder="System Variable Name" value="${variable.title }"/>
									<div class="variableTypes variableTypeOption panel panel-default variablePanel">
										<c:forTokens items="${variable.opt }" delims=";"  var="opt">
										<div class='panel-body optionRows'>
											<div class="input-group">
												<span class="input-group-addon"><input type="radio" class="variableOptions" name="vals" id="vals" value="${opt }" <c:if test="${opt eq variable.val }">checked="checked"</c:if> name="variables[${status.index }].vals"></span>
										      	<input type="text" class="form-control variableOptions" name="opts" id="opts" placeholder='System Variable Option Value' value="${opt }">
										      	<input type='hidden' class='form-control' name='rows' id='rows' placeholder='System Variable Value'  value="${variable.cols }"/>
												<input type='hidden' class='form-control' name='cols' id='cols' placeholder='System Variable Value' value="${variable.rows }"/>
										      	<span class="input-group-btn">
										        	<button class="btn btn-default deleteOptionRow" type="button"><spring:message code='button.delete'/></button>
										      	</span>
										    </div>
										</div>
										</c:forTokens>
									</div>
								</td>
							</c:when>
							<c:when test="${variable.array }">
								<td class="col-sm-8">
									<div class='col-sm-12'>
										<div class='col-sm-5'><input type='text' name='title' id='title' class='form-control' placeholder='' value="${variable.title }"/></div>
										<div class='col-sm-4'>
											<select id='cdtArraySelect' class='form-control cdtArraySelect' required='required'>
												<option value=''><spring:message code='select.seleted.message'/></option>
												<c:forEach items="${cdts }" var="cdt">
													<c:choose>
														<c:when test="${variable.refUserTypeId eq cdt.userTypeId}"><option value='${cdt.userTypeId }' selected="selected">${cdt.userTypeName }</option></c:when>
														<c:otherwise><option value='${cdt.userTypeId }'>${cdt.userTypeName }</option></c:otherwise>
													</c:choose>
												</c:forEach>
											</select>
										</div>
										<div class='col-sm-3'><button type='button' class='btn btn-primary addCdtArrayRows'><spring:message code='button.add.rows'/></button></div>
									</div>
									<table class='table table-striped topmargin50 cdtArrayTable'>
										<thead><tr>
										<c:forEach items="${variable.arrays }" var="variableArray" varStatus="varrayStatus">
											<c:if test="${varrayStatus.first}">
												<c:forEach items="${variableArray }" var="tds">
													<th>${tds.header }</th>
												</c:forEach>
												<th></th>
											</c:if>
										</c:forEach>
										</tr></thead>
										<tbody>
										<c:forEach items="${variable.arrays }" var="variableArray" varStatus="varrayStatus">
											<tr>
												<c:forEach items="${variableArray }" var="tds">
													<td>
													<c:choose>
														<c:when test="${(tds.tp eq 'String') or (tds.tp eq 'Integer') or (tds.tp eq 'Double') }">
															<input type="text" id='val' name='val' value="${tds.val }" class="form-control"/>
															<input type='hidden' id='header' name='header' value='${tds.header }'/>
															<input type='hidden' id='tp' name='tp' value='${tds.tp }'/>
														</c:when>
														<c:otherwise><!-- Option -->
															<select name='opt' id='opt' class="form-control">
																<c:forTokens items="${tds.opt }" delims=";"  var="opt">
																<c:choose>
																	<c:when test="${opt eq tds.val }"><option value="${opt }" selected="selected">${opt }</option></c:when>
																	<c:otherwise><option value="${opt }">${opt }</option></c:otherwise>
																</c:choose>
																</c:forTokens>
															</select>
															<input type="hidden" id='val' name='val' value="${tds.val }"/>
															<input type='hidden' id='header' name='header' value='${tds.header }'/>
															<input type='hidden' id='tp' name='tp' value='${tds.tp }'/>
														</c:otherwise>
													</c:choose>
													</td>
												</c:forEach>
												<td><button class='btn btn-warning cdtRowDeleteBtn'><spring:message code='button.delete'/></button></td>
											</tr>
										</c:forEach>
										</tbody>
									</table>
								</td>
							</c:when>
						</c:choose>
						<td class="col-sm-1">
							<button type="button" class="btn btn-warning removeRows"><spring:message code="button.delete"/></button>
						</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
	</div>
	<div class="form-group">
		<div class="col-sm-12 text-right">
		<button class="btn btn-default btn_link btn_show_group" data-link="./lists" type="button"><spring:message code="button.list"/></button>
		<c:if test="${fn:contains(buttons , Authorities.UPDATE)}">
		<button class="btn btn-primary updateBtn btn_show_group" type="button"><spring:message code="button.edit"/></button>
		<button class="btn btn-success updateSubmitBtn btn_show_group" type="button"><spring:message code="button.edit"/></button>
		</c:if>
		<c:if test="${fn:contains(buttons , Authorities.REMOVE)}">
		<button class="btn btn-primary removeBtn btn_show_group" type="button"><spring:message code="button.delete"/></button>
		</c:if>
		</div>
	</div>
</form:form>
<div class="variableHiddenTable variableMapTable">
	<table class="table table-hover">
		<tr class="templateVariableRow">
			<td class="col-sm-2 selectRows">
				<select class="form-control variableTypesSelect" name="tp" id="tp" required='required'>
					<option value=""><spring:message code="select.seleted.message"/></option>
					<option value="String">String</option>
					<option value="Integer">Integer</option>
					<option value="Double">Double</option>
					<option value="Option">Option</option>
					<option value="Array">Array</option>
				</select>
				<button type='button' class='btn btn-default addOptionButton variablePanel'><spring:message code='button.add.option'/></button>
			</td>
			<td class="col-sm-8">
				<div class="variableTypes variableTypeArray panel panel-default variablePanel">
				</div>
			</td>
			<td class="col-sm-1"><button type="button" class="btn btn-warning removeRows"><spring:message code="button.delete"/></button></td>
		</tr>
	</table>
</div>
<div class="variableHiddenTable variableSingleValueTable">
	<table>
		<tr>
			<td class="col-sm-8">
				<input type="text" class="form-control" name="title" value="" required='required' placeholder="System Variable Name"/>
				<div class="variableTypes variableTypeSingleValue panel panel-default variablePanel">
					<div class='panel-body'>
						<input type='text' class='form-control' name='val' placeholder='System Variable Value'/>
					</div>
				</div>
			</td>
			<td class="col-sm-1"><button type="button" class="btn btn-warning removeRows"><spring:message code="button.delete"/></button></td>
		</tr>
	</table>
</div>
<div class="variableHiddenTable variableOptionTable">
	<table>
		<tr>
			<td class="col-sm-8">
				<input type="text" class="form-control" id="title" name="title" required='required' value="" placeholder="System Variable Name"/>
				<div class="variableTypes variableTypeOption panel panel-default variablePanel">
					<div class='panel-body optionRows'>
						<div class="input-group"><span class="input-group-addon"><input type="radio" class="variableOptions" name="vals"></span>
					      	<input type="text" class="form-control variableOptions" name="opts" id="opts" placeholder='System Variable Option Value'>
					      	<span class="input-group-btn">
					        	<button class="btn btn-default deleteOptionRow" type="button"><spring:message code='button.delete'/></button>
					      	</span>
					    </div>
					</div>
				</div>
			</td>
			<td class="col-sm-1"><button type="button" class="btn btn-warning removeRows"><spring:message code="button.delete"/></button></td>
		</tr>
	</table>
</div>
<div class="variableHiddenTable variableArrayTable">
	<table>
		<tr>
			<td class="col-sm-8">
				<div class="variableTypes variableTypeArray panel panel-default variablePanel">
					<div class='panel-body'></div>
				</div>
			</td>
			<td class="col-sm-1"><button type="button" class="btn btn-warning removeRows"><spring:message code="button.delete"/></button></td>
		</tr>
	</table>
</div>
<div class="variableHiddenTable variableDefaultTable">
	<table>
		<tr>
			<td class="col-sm-8">
				<div class="variableTypes variableTypeArray panel panel-default variablePanel"></div>
			</td>
			<td class="col-sm-1"><button type="button" class="btn btn-warning removeRows"><spring:message code="button.delete"/></button></td>
		</tr>
	</table>
</div>
<div class="variableHiddenTable variableHiddenOptionValues">
<input type="hidden" class="form-control variableOption" data-prefix='variables[' data-surfix='].opt' value="">
<input type="hidden" class="form-control variableOptionValue" data-prefix='variables[' data-surfix='].val' value="">
</div>
<script type="text/javascript"><!--
function doMakeData() {
	var trs = $(".targetVariableMapTable>tbody>tr");
	var metadatas = [];
	$.each(trs, function(index, item) {
		var metadata = { "title" : "", "array" : "", "arrayRow":"", "cols" : "", "rows" : "", "opt" : "", "tp" : "", "val" : "", "refUserTypeId" : "","header" : ""};
		var variable_tp = $(this).find("td:eq(0)").find(":input[name='tp'] option:selected").val();
		switch(variable_tp) {
		case "String":
		case "Integer":
		case "Double":
			metadata.title = $(this).find("td:eq(1)").find(":input[name='title']").val();
			metadata.header = "";
			metadata.array = 0;
			metadata.arrayRow = -1;
			metadata.cols = 1;
			metadata.rows = 1;
			metadata.opt = "";
			metadata.tp = variable_tp;
			metadata.refUserTypeId = "";
			metadata.val = $(this).find("td:eq(1)").find(":input[name='val']").val();
			metadatas.push(metadata);
			break;
		case "Option":
			metadata.title = $(this).find("td:eq(1)").find(":input[name='title']").val();
			metadata.header = "";
			metadata.array = 0;
			metadata.arrayRow = -1;
			metadata.cols = 1;
			metadata.rows = 1;
			var opts = [];
			$.each($(this).find("td:eq(1)").find(":input[name='opts']"), function() {
				opts.push($(this).val());
			});
			metadata.opt = opts.join(";");
			metadata.tp = variable_tp;
			metadata.refUserTypeId = "";
			metadata.val = $(this).find("td:eq(1)").find(":input[name='vals']:checked").parent().parent().find(":input[name='opts']").val();
			metadatas.push(metadata);
			break;
 		case "Array":
 			var arrayTable = $(this).find("td:eq(1)").find("table>tbody");
 			var arrayTableTr = arrayTable.find("tr"); 
 			$.each(arrayTableTr, function(trIndex, trItem) {
 				var arrayTableTd = $(this).find("td"); 
 				$.each(arrayTableTd, function(tdIndex, tdItem){
 					var isTarget = $(this).find(":input[name='header']").attr("name") == 'header';
 					if (isTarget) {
 						metadata = { "title" : "", "array" : "", "arrayRow":"", "cols" : "", "rows" : "", "opt" : "", "tp" : "", "val" : "", "refUserTypeId" : "","header" : ""};
 	 	 				metadata.header = $(this).find(":input[name='header']").val();
 	 	 				metadata.title = $(this).parent().parent().parent().parent().find(":input[name='title']").val();
 	 	 				metadata.array = 1;
 	 	 				metadata.arrayRow = index;
 	 	 				metadata.cols = tdIndex;
 	 	 				metadata.rows = trIndex;
 	 	 				metadata.tp = $(this).find(":input[name='tp']").val();
 	 	 				metadata.refUserTypeId = $(this).parent().parent().parent().parent().parent().find(".cdtArraySelect option:selected").val();
 	 	 				switch(metadata.tp) {
 	 	 				case "String":
 	 	 				case "Integer":
 	 	 				case "Double":
 	 	 					metadata.opt = "";
 	 	 					metadata.val = $(this).find(":input[name='val']").val();
 	 	 					break;
 	 	 				case "Option":
 	 	 					var opts = [];
 	 	 					$.each($(this).find(":input[name='opt'] option"), function() {
 	 	 						opts.push($(this).val());
 	 	 					});
 	 	 					metadata.opt = opts.join(";");
 	 	 					metadata.val = $(this).find(":input[name='opt'] option:selected").val();
 	 	 					break;
 	 	 				}
 	 	 				metadatas.push(metadata); 						
 					}
 	 			}); 				
 			});
			break;
		}
	});
	
	var sevs = {
			"variableid" : $("#variableid").val(),
			"variableName" : $("#variableName").val(),
			"variableDesc" : $("#variableDesc").val(),
			"variableLimitId" : $("#variableLimitId").val(),
			"variables" : metadatas,
		}
	
	return sevs;
}

$(document).ready(function() {
	var cdts;
	$(".variableHiddenTable").hide();
	$(".addOptionButton").hide();
	
	$(".updateSubmitBtn").hide();
	$(".addRows").attr("disabled","true");
	$(".form-horizontal").find(":input").attr("disabled","true");
	$(".btn_show_group").removeAttr("disabled");
		
	
	/* Option 변경 시, 해당 Table 추가 */
	$(document).on("change", ".variableTypesSelect", function() {
		var targetHiddenTable = $(this).parent().parent().find(".variableTypeArea");
		var selectedOption = $(this).find("option:selected").val();
		targetHiddenTable.show();
		$(this).parent().parent().find("td:gt(0)").remove();
		switch(selectedOption) {
		case "Array":
			var copyTd = $(".variableArrayTable").find("td").clone();
			$(this).parent().parent().append(copyTd);
			$(this).parent().find(".addOptionButton").hide();
			$(this).parent().parent().find(".variableTypes").hide();
			var targetTd = $(this).parent().parent().find(".variableTypeArray");
			var appendTd = targetTd.find(".panel-body");
			targetTd.show();
			Loading.show();
			$.get("${CONTEXT}/rest/cdt/getCdts.json", null, function(resultJson) {
				cdts = resultJson;
				var arrays = "";
				arrays += "<div class='col-sm-12'>";
				arrays += "<div class='col-sm-5'><input type='text' name='title' id='title' required='required' class='form-control'/></div>";
				arrays += "<div class='col-sm-4'><select id='cdtArraySelect' class='form-control cdtArraySelect' required='required'>";
				arrays += "<option value=''><spring:message code='select.seleted.message'/></option>";
				$.each(resultJson, function(index, item) {
					arrays += "<option value='"+item.userTypeId+"'>"+item.userTypeName+"</option>";
				});
				arrays += "</select></div>";
				arrays += "<div class='col-sm-3'><button type='button' class='btn btn-primary addCdtArrayRows'><spring:message code='button.add.rows'/></button></div>";
				arrays += "</div>";
				appendTd.append(arrays);
			}).always(function() {
				Loading.hide();
			});
			break;
		case "Option":
			var copyTd = $(".variableOptionTable").find("td").clone();
			var hiddenValues = $(".variableHiddenOptionValues").find(":input");
			$(this).parent().parent().append(copyTd);
			$(this).parent().find(".addOptionButton").show();
			$(this).parent().append(hiddenValues);
			$(this).parent().parent().find(".variableTypes").hide();
			var targetRow = $(this).parent().parent().find(".variableTypeOption");
			targetRow.removeClass("optionRows");
			targetRow.show();
			break;
		case "Integer":
		case "Double":
		case "String":
			var copyTd = $(".variableSingleValueTable").find("td").clone();
			$(this).parent().parent().append(copyTd);
			$(this).parent().find(".addOptionButton").hide();
			$(this).parent().parent().find(".variableTypes").hide();
			$(this).parent().parent().find(".variableTypeSingleValue").show();
			break;
		default:
			var copyTd = $(".variableDefaultTable").find("td").clone();
			$(this).parent().parent().append(copyTd);
			$(this).parent().find(".addOptionButton").hide();
			$(this).parent().parent().find(".variableTypes").hide();
			$(this).parent().parent().find(".variableTypeSingleValue").show();
			break;
		}
	}).on("click", ".addRows", function() {
		var templateRow = $(".templateVariableRow");
		var copyRow = templateRow.clone();
		copyRow.removeClass("templateVariableRow");
		$(".targetVariableMapTable").append(copyRow);
	}).on("click", ".addOptionButton", function() {
		var optionTemplate = $(".variableOptionTable").find(".optionRows").clone();
		$(this).parent().parent().find(".variableTypeOption").append(optionTemplate);
	}).on("click", ".deleteOptionRow", function() {
		$(this).parent().parent().parent().remove();
	}).on("click", ".removeRows", function() {
		$(this).parent().parent().remove();
	}).on("click", ".addCdtArrayRows", function(){
		var that = $(this).parent().parent().parent().find("table");
		var cloneTr = that.find("tr:last").clone();
		that.append(cloneTr);
	}).on("click", ".cdtRowDeleteBtn", function() {
		$(this).parent().parent().remove();
	}).on("change", ".cdtArraySelect", function() {
		var arrayTable = "<table class='table table-striped topmargin50 cdtArrayTable'><thead><tr>";
		var that = $(this);
		that.parent().parent().parent().find("table").remove();
		if ( that.find("option:selected").val() != "" ) {
			var rows = 1;
			var cols = 1;
			$.each(cdts, function(index, item) {
				if ( item.userTypeId == that.find("option:selected").val()) {
					if ( index == 0 ) {
						$.each(item.rows, function(inIndex, inItem) {
							arrayTable+="<th>"+inItem.columnName+"</th>";
						});
						arrayTable+="<th></th></tr></thead><tbody>";
					}
					arrayTable+="<tr>";
					$.each(item.rows, function(inIndex, inItem) {
						cols++;
						switch(inItem.columnType) {
						case 'String':
						case 'Integer':
						case 'Double':
							arrayTable+="<td><input type='text' id='val' name='val' class='form-control' value='"+inItem.defaultValue+"'/>";
							arrayTable+="<input type='hidden' id='header' name='header' value='"+inItem.columnName+"'/>";
							arrayTable+="<input type='hidden' id='tp' name='tp' value='String'/>";
							arrayTable+="</td>";
							break;
						case 'Option':
							arrayTable+="<td>";
							arrayTable+="<select name='opt' id='opt' class='form-control'>";
							var options = inItem.columnTypeOption.split(";");
							for(var i=0;i<options.length;i++) {
								if ( inItem.defaultValue == options[i] ) {
									arrayTable+="<option value='"+options[i]+"' selected='selected'>"+options[i]+"</options>";
								} else {
									arrayTable+="<option value='"+options[i]+"'>"+options[i]+"</options>";									
								}
							}
							arrayTable+="</select>";
							arrayTable+="<input type='hidden' id='header' name='header' value='"+inItem.columnName+"'/>";
							arrayTable+="<input type='hidden' id='val' name='val' value=''/>";
							arrayTable+="<input type='hidden' id='tp' name='tp' value='Option'/>";
							arrayTable+="</td>";
							break;
						}
					});
					arrayTable+="<td><button class='btn btn-warning cdtRowDeleteBtn'><spring:message code='button.delete'/></button></td>";
					arrayTable+="</tr>";
					rows++;
				}
			});
			arrayTable+="</tbody></table>";
			that.parent().parent().parent().append(arrayTable);
		}
	}).on("click", ".removeBtn", function() {
		bootbox.confirm("<spring:message code='common.remove.confirm'/>", function(result) {
			if ( result ) {
				Loading.show();
				$(".form-horizontal").find(":input").removeAttr("disabled");
				var param = { "sevEntityData" :  JSON.stringify(doMakeData())};
				$.post("./remove", param, function(res) {
					
				}).fail(function() {
					bootbox.alert("<spring:message code='common.server.fail'/>"); /* 서버 통신 오류 */
				}).done(function(res) {
					if ( res ) {
						bootbox.alert("<spring:message code='common.remove.ok'/>", function() {
							Loading.link("./lists");							
						});
					} else {
						bootbox.alert("<spring:message code='common.remove.fail'/>");
					}
				}).always(function() {
					Loading.hide();
				});
			}
		});
	}).on("click", ".updateSubmitBtn", function() {
		bootbox.confirm("<spring:message code='common.update.confirm'/>", function(result) {
			Notification.show("Confirm result: "+result);
			if ( result ) {
				Loading.show();
				var variableOpt = [];
				$(".targetVariableMapTable").find(":input:text").each(function(index, item){
					if ($(this).data("surfix") == "].opts" ) {
						variableOpt.push($(this).val());
						$(this).parent().parent().parent().parent().find(".variableOption").val(variableOpt.join(";"));
					}
				});
				var param = { "sevEntityData" :  JSON.stringify(doMakeData())};
				$.post("./edit", param, function(res) {
					
				}).fail(function() {
					bootbox.alert("<spring:message code='common.server.fail'/>"); /* 서버 통신 오류 */
				}).done(function(res) {
					if ( res ) {
						bootbox.alert("<spring:message code='common.update.ok'/>", function() {
							Loading.link("./lists");							
						});
					} else {
						bootbox.alert("<spring:message code='common.update.fail'/>");
					}
				}).always(function() {
					Loading.hide();
				});
			}
		});
	}).on("click", ".updateBtn", function() {
		$(".form-horizontal").find(":input").removeAttr("disabled");
		$(".removeRows").show();
		$(".addRows").show();
		$(".updateSubmitBtn").show();
		$(this).hide();
	});
});
//--></script>